package com.cytech.cloudclinic.moudle.main.patient.detail.caseinfo;

import android.os.Bundle;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.cytech.cloudclinic.R;
import com.cytech.cloudclinic.adapter.CaseInfoAdapter;
import com.cytech.cloudclinic.base.BaseFragment;
import com.cytech.cloudclinic.bean.CaseInfo;
import com.cytech.cloudclinic.moudle.main.patient.detail.base.PatientDetailBaseFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class PatientDetailCaseFragment extends BaseFragment<PatientDetailCasePresenter> implements PatientDetailCaseView {
    @BindView(R.id.rv_patient_detail_case)
    RecyclerView recyclerView;

    private List<CaseInfo> mList;
    private CaseInfoAdapter mAdapter;

    private int patientId;

    public static PatientDetailCaseFragment newInstance(int patientId) {
        PatientDetailCaseFragment fragment = new PatientDetailCaseFragment();
        //如果有参数，使用Bundle传递
        Bundle bundle = new Bundle();
        bundle.putInt("patientId", patientId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected PatientDetailCasePresenter createPresenter() {
        return new PatientDetailCasePresenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_patient_detail_case;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        patientId = getArguments().getInt("patientId");
        mList = new ArrayList<>();
        mAdapter = new CaseInfoAdapter(mList);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.setAdapter(mAdapter);
        presenter.getPatientCase(patientId);
    }


    @Override
    public void getPatientCaseListSuccess(List<CaseInfo> data) {
        mAdapter.setNewInstance(data);
    }
}
